Repository navigation
[JSC] Predict the empty value for an unprofiled load of this of a derived constructor from its scope - #1017
Draft
robobun wants to merge 1 commit into
Draft
[JSC] Predict the empty value for an unprofiled load of this of a derived constructor from its scope#1017robobun wants to merge 1 commit into
this of a derived constructor from its scope#1017robobun wants to merge 1 commit into
Conversation
…ctor from its scope for a load of the empty value
An arrow function that calls super() first reads `this` of its derived constructor from the scope, to throw if
a super() came before. On each valid path that value is empty, and a value profile does not record the empty
value. So the DFG finds a load with no prediction, takes what follows for code that did not run yet, and plants
ForceOSRExit there. Each call of the arrow function then leaves the optimized code at that load.
class Derived extends Base {
constructor()
{
const __super = (...args) => { super(...args); this.field = 2; return this; };
__super();
}
}
esbuild makes such a helper for a class whose fields it lowers. In 60,000 constructions the DFG compiles
__super 8 times and its code exits 25,508 times. A construction takes 1072 instructions (release jsc,
--useConcurrentJIT=0, instructions:u). With this change the DFG compiles it once, there is no exit in it, and a
construction takes 80 instructions.
op_get_from_scope has the answer for ResolvedClosureVar already: the prediction is SpecEmpty where the profile
says SpecNone. The same now holds for the name of `this` in a scope (thisPrivateName).
Test: JSTests/stress/dfg-arrow-function-with-super-call-is-compiled-once.js
This was referenced Nov 9, 2026
Open
|
Preview build of 89d38c4: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft on purpose: for WebKit/WebKit first. See Route in Notes.
Problem
super()leaves optimized code again and again. The DFG compiles esbuild's__superhelper 8 times in 60,000 constructions, with 25,508 exits (bc#8,InadequateCoverage).thisfrom the scope, to throw if asuper()came before. The value is empty each time, and a value profile does not record that. Soop_get_from_scope(DFGByteCodeParser.cpp:10930) has no prediction and plantsForceOSRExit.Fix
op_get_from_scopepredictsSpecEmptyfor the name ofthisin a scope when the profile saysSpecNone, as it does forResolvedClosureVar.jsc,instructions:u).JSTests/stress/dfg-arrow-function-with-super-call-is-compiled-once.js(new, fails on the base: "the DFG compiled initialize 6 times"). Self-reviewed: 2 concerns raised, 2 addressed (Notes).Background
thisof a derived constructor has no value beforesuper()returns: its scope slot holds the empty value.Downsides
thisthat first runs after the DFG compile: 178.7 against 179.1 instructions per construction in the DFG, 72.4 against 73.3 in all tiers. Releasejschas the samesize.Notes
Route. This PR does not ask for a merge into the fork as it stands.
ArrayStorage(cherry-pick WebKit/WebKit#75376) #785 and [JSC] IRO's ArithAbs transform can pin freed range bound proofs (cherry-pick WebKit/WebKit#72679) #530 were. Or it closes when a sync brings that commit and the test of this branch passes on thatmain.thiscan take) and of [JSC] Arrow functions and eval code of a derived constructor readthisat each use when other code of the constructor can call super() #1018 (other arrow functions of such a constructor readthisat each use).Numbers. Release
jscof 5a61071 and of this branch,--useConcurrentJIT=0.const __super = (...args) => { super(...args); this.field = 2; return this; }, 60,000 constructions: DFG compiles of__super__super(--printEachOSRExit=1)--useFTLJIT=0super()in different forms and then usethis, 12,000 constructions each: DFG compiles--useBytecodeOptimizer=1ResolvedClosureVar, so the existing rule applies. That is why a bytecode image does not have the loop.The rule for
ResolvedClosureVar. Its comment says that the empty value is a legitimate result there, and that a value profile cannot say so. Both hold forthisof a derived constructor in a scope: the load in front of the check for a secondsuper()gives the empty value on every path that does not throw.What the prediction changes. A prediction is a hint.
GetClosureVarcan still give any value, and thecheck_tdzandis_emptythat follow the load are compiled as before. The test runs the check for a secondsuper()in optimized code.Self-review. The review of #1018 asked for this line as a change of its own, with 1 DFG compile and no exit as the bar, and for a PR of its own. Both are done.
Test runs. The new test runs with
--useConcurrentJIT=0. It fails on debug and release builds of the base and passes on both builds of this branch. A debug build with ASAN that has this PR, #1016 and #1018 passes the three new tests in every mode ofrun-jsc-stress-tests. 5,501 runs of other stress tests on that build, most of them in the twodfg-eagermodes: 7 failures, stack overflows and a memory limit, which the base has too.